package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-09-12
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论表的增删改查")
public class CommentController {

    @Autowired
    CommentService commentService;

    /**
      * @Author: zqh
      * @Date:
      * @Description: 添加一条新评论
    */
    @ApiOperation(value = "添加一条新评论")
    @PostMapping("addANewComment")
    public RespBean addANewComment(Integer shop_id, String comment, Principal principal){
        return commentService.addANewComment(shop_id,comment,principal);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 查询评论
    */
    @ApiOperation(value = "查询评论（放行）")
    @GetMapping("queryComments")
    public RespBean queryComments(Integer shop_id){
        return commentService.queryComments(shop_id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 删除评论
    */
    @ApiOperation(value = "删除评论（需要管理员权限）")
    @PreAuthorize("hasRole('ROLE_admin')")
    @DeleteMapping("deleteComment")
    public RespBean deleteComment(Integer id){
        return commentService.deleteComment(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 评论点赞
    */
    @ApiOperation(value = "评论点赞")
    @PostMapping("commentLike")
    public RespBean commentLike(Integer id){
        return commentService.commentLike(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取某个店铺评论的数量
    */
    @ApiOperation(value = "获取某个店铺评论的数量（放行）")
    @GetMapping("getCommentNumber")
    public RespBean getCommentNumber(Integer shop_id){
        return commentService.getCommentNumber(shop_id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取所有评论的数量
    */
    @ApiOperation(value = "获取所有评论的数量")
    @GetMapping("getAllNumberComment")
    public RespBean getAllNumberComment(){
        return commentService.getAllNumberComment();
    }


}

